package com.bocai.service.impl;

import com.bocai.bean.CountryInfo;
import com.bocai.mapper.CountryInfoMapper;
import com.bocai.service.ICountryService;
import com.bocai.utils.CodeEnum;
import com.bocai.utils.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CountryServiceImpl implements ICountryService {

    @Autowired
    private CountryInfoMapper countryInfoMapper;

    @Override
    public int insertCountrys(List<CountryInfo> countryInfos) {
        for (CountryInfo countryInfo : countryInfos){
            this.countryInfoMapper.insertSelective(countryInfo);
        }

        return 0;
    }

    @Override
    public int updateCountrys(List<CountryInfo> countryInfos) {
        for (CountryInfo countryInfo : countryInfos){
            this.countryInfoMapper.updateByPrimaryKeySelective(countryInfo);
        }
        return 0;
    }

    @Override
    public ResponseData selectAllCountry(ResponseData data) {
        data.setCodeEnum(CodeEnum.SUCCESS);

        data.setResults(this.countryInfoMapper.selectAllCountrys());

        return data;
    }
}
